<template>
	<view class="page">
		<div style="font-size: 18px;font-weight: bold;margin-top: 12px;align-self: center;">恭喜抢购成功</div>
		<div style="font-size: 12px;font-weight: bold;margin-top: 12px;align-self: center;color: #808080;">完善下面信息并支付完成购买
		</div>

		<div
			style="padding: 12px;background-color: #FFFFFF;display: flex;align-items: center;border-bottom: 1px solid #ebebeb;margin-top: 20px;">
			<div style="width:90px">订单号:</div>
			<div style="margin-left: 12px;">{{data.orderNo}}</div>
		</div>
		<div
			style="padding: 12px;background-color: #FFFFFF;display: flex;align-items: center;border-bottom: 1px solid #ebebeb;">
			<div style="width: 90px;">订单金额:</div>
			<div style="margin-left: 12px;">¥{{data.orderAmount}}</div>
		</div>

		<div style="display: flex;background-color: #ffffff;padding: 12px;border-bottom: 1px solid #ebebeb;">
			<div style="width:90px;">姓名</div>
			<input type="text" value="" placeholder="请输入姓名" style="margin-left: 12px;" v-model="info.contactName" />
		</div>
		<div style="display: flex;background-color: #ffffff;padding: 12px;border-bottom: 1px solid #ebebeb;">
			<div style="width:90px;">手机号/微信</div>
			<input type="text" value="" placeholder="请输入手机号" style="margin-left: 12px;"
				v-model="info.contactInformation" />
		</div>
		<div style="display: flex;background-color: #ffffff;padding: 12px;border-bottom: 1px solid #ebebeb;">
			<div style="width:90px;">备注</div>
			<textarea type="text" value="" placeholder="请输入姓名" style="margin-left: 25px;" v-model="info.remark" />
		</div>
		<div @click="payHandle"
			style="padding: 12px 0;background-color: #00aa00;color: #FFFFFF;text-align: center;margin-top: 40px;border-radius: 4px;margin-left: 20px;margin-right: 20px;">
			立即支付</div>
	</view>
</template>

<script>
	import api from "@/request.js"
	export default {
		data() {
			return {
				wxcode: undefined,
				info: {
					contactInformation: "",
					contactName: "",
					orderNo: "",
					remark: "",
					userIp: "",
				},
				data: {}
			}
		},
		onLoad(option) {
			this.data = JSON.parse(decodeURIComponent(option.data))
		},
		mounted() {
			//############################################
			let token = uni.getStorageSync("token")
			if(token == undefined || token.length == 0) {
				uni.redirectTo({
					url:"../../login/login"
				})
				return;
			}
			//############################################
			
			
			this.info.orderNo = this.data.orderNo
			this.wxcode = uni.getStorageSync("wxcode")
		},
		methods: {
			back() {
				uni.navigateBack({

				})
			},
			payHandle() {
				let self = this
				let body = {
					...this.info,
					code: this.wxcode,
				}
				api({
					url: "/api/admin/seckill/order/payOrder",
					method: 'post',
					data: body
				}).then(res => {
					let {
						msg
					} = res;
					let data = JSON.parse(msg)
					self.wxPayHandle(data)
				}).catch(e => {
					uni.showToast({
						title: e
					})
				});
			},
			wxPayHandle(payargs) {
				let fi = {
					appid:payargs.appId,
					timeStamp: payargs.timeStamp,
					nonceStr: payargs.nonceStr,
					package: payargs.package,
					signType: payargs.signType,
					paySign: payargs.paySign,
				}

				wx.requestPayment({
					...fi,
					success(res) {
						debugger
						if (res.errMsg == "requestPayment:ok") {
							uni.reLaunch({
								url: "../payresult/payresult"
							})
							console.log(res)
						} else {
							uni.showToast({
								title: JSON.stringify(res),
								icon: "none"
							})
						}
					},
					fail(res) {
						debugger
						if (res.errMsg == "requestPayment:cancel") {
							uni.showToast({
								title: "您取消支付",
								icon: "none",
								duration:2000
							})
							return
						}
						uni.showToast({
							title: JSON.stringify(res),
							icon: "none",
							duration:10000
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.page {
		flex: 1;
		width: 100%;
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
	}
</style>
